//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_spectatingLoad.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

_list_name = [name player];
_list_units = [player];
switch (true) do
{
	case (BTC_spectating == 1) : {{if (_x != player) then {_list_name = _list_name + [name _x];_list_units = _list_units + [_x];};} foreach units group player;};
	case (BTC_spectating == 2) : {{if (side _x == BTC_side && _x != player) then {_list_name = _list_name + [name _x];_list_units = _list_units + [_x];};} foreach (if (isMultiplayer) then { playableUnits } else { switchableUnits });};//switchableunits
	case (BTC_spectating == 3) : {{if (_x != player) then {_list_name = _list_name + [name _x];_list_units = _list_units + [_x];};} foreach (if (isMultiplayer) then { playableUnits } else { switchableUnits });};
};
_n = 0;
if (!isNull BTC_r_s_target && BTC_r_s_target != BTC_r_base_spawn) then {if ((_list_name find (name BTC_r_s_target)) == -1) then {BTC_r_s_target = BTC_r_base_spawn;};};
if (count _list_name != count BTC_r_s_list) then 
{
	lbClear 120;
	{
		_lb = lbAdd [120,_x];
		if (!isNull BTC_r_s_target && BTC_r_s_target != BTC_r_base_spawn) then {if (name BTC_r_s_target == _x) then {lbSetCurSel [120,_lb];};};
		if (isNull BTC_r_s_target) then {lbSetCurSel [120,_lb];_n = _list_name find _x;BTC_r_s_target = _list_units select _n;};
	} foreach _list_name;BTC_r_s_list = _list_name;
} else {};
if (count _list_name == 0) then {titleText ["No units found!","PLAIN DOWN"];BTC_r_s_target = BTC_r_base_spawn;} else {titleText ["","PLAIN DOWN"];};
if (count BTC_r_s_list > 0 && {lbCurSel 120 < 0}) then { lbSetCurSel [120,0]; };
TRACE_1("End",ARR_4(BTC_spectating,BTC_r_s_target,BTC_r_s_list,_list_units));
true
